package sz.szsmk.citizencard.ui.adapter;

import android.content.Context;
import androidx.recyclerview.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.ViewGroup;

import com.alibaba.android.vlayout.DelegateAdapter;
import com.alibaba.android.vlayout.LayoutHelper;
import com.alibaba.android.vlayout.layout.DefaultLayoutHelper;
import com.bumptech.glide.Glide;
import sz.szsmk.citizencard.R;
import sz.szsmk.citizencard.databinding.UserAdaverViewBinding;

/**
 * Copyright (c)2018
 * author: zdh
 * created on: 2018/7/9 10:50
 * description:我的广告适配器
 */
public class UserAdaverAdapter extends DelegateAdapter.Adapter<UserAdaverAdapter.UserAdaverHolder> {

    private Context mContext;
    private LayoutHelper mGridLayoutHelper;
    private String url = "https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=3082898347,3637224891&fm=27&gp=0.jpg";

    public UserAdaverAdapter(Context context, DefaultLayoutHelper adverHelper) {
        mContext = context;
        mGridLayoutHelper = adverHelper;
    }

    @Override
    public LayoutHelper onCreateLayoutHelper() {
        return mGridLayoutHelper;
    }

    @Override
    public int getItemViewType(int position) {
        return R.layout.user_adaver_view;
    }

    @Override
    public int getItemCount() {
        return 1;
    }

    @Override
    public void onBindViewHolder(UserAdaverHolder holder, int position) {
        loadItemData(position,holder.binding);
    }

    private void loadItemData(int position, UserAdaverViewBinding binding) {
        binding.userAdaverIc.setImageResource(R.drawable.background_card);
        Glide.with(mContext)
                .load(url)
                .override(140, 80)
                .into(binding.userAdaverIc);
    }

    @Override
    public UserAdaverHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return UserAdaverHolder.creat(parent);
    }


    public static class UserAdaverHolder extends RecyclerView.ViewHolder {

        public UserAdaverViewBinding binding;

        public static UserAdaverHolder creat(ViewGroup parent){
            UserAdaverViewBinding binding = UserAdaverViewBinding
                    .inflate(LayoutInflater.from(parent.getContext()), parent, false);

            return new UserAdaverHolder(binding);
        }

        public UserAdaverHolder(UserAdaverViewBinding binding) {
            super(binding.getRoot());
            this.binding = binding;
        }
    }

}
